<?php

namespace App\Repositories\Eloquent\Api;

use App\Repositories\Eloquent\BaseModel;
use EasySwoole\ORM\AbstractModel;


class MemberOnlineModel extends AbstractModel
{
    use BaseModel;
    protected $tableName = 'k_user_online';
    protected $connectionName = 'wr';
    protected $autoTimeStamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';

    public function getItemByMemberId(int $memberId = 0){
        return $this->create()->get(['id_user'=>$memberId]);
    }

    public function getItemByKey(string $key = ''){
        return $this->create->get(['login_key'=>$key]);
    }

    public function setOnlineActiveTime(int $memberId = 0){
        $obj = $this->create()->get(['id_user'=>$memberId]);
        $obj->active_time = time();
        $obj->update();
    }

    public function delByMemberId(int $memberId = 0){
        $this->create()->destroy(['id_user' => $memberId]);
    }

    public function getCountByMemberId(int $memberId = 0){
        return $this->create()->where(['id_user'=>$memberId])->count();

    }

}